<template>
	<view class="p1">
		<view class="p2">
			<text>手机号：</text>
			<input type="text" placeholder="请输入手机号" v-model="phonenumber"/>
		</view>
		<u-line></u-line>
		<view class="p2">
			<text>昵称：</text>
			<input  type="text" placeholder="请输入昵称" v-model="nickName"/>
		</view>
		<u-line></u-line>
		<view class="p2">
			<text>邮箱：</text>
			<input  type="text" placeholder="请输入邮箱" v-model="email"/>
		</view>
		<u-line></u-line>
		<u--form style="margin-top: 15px; margin-bottom: 15px;">
			<u-form-item label="性别:" @click="show=true">
				<u-input placeholder="请选择性别" border="none" v-model="sex"></u-input>
				<u-icon slot="right"name="arrow-right"></u-icon>
			</u-form-item>
		</u--form>
		<u-action-sheet :show="show" title="请选择性别" :actions="actions" @close="show=false" @select="selectsex"></u-action-sheet>
		<u-button text="提交" type="primary" :plain="true" @click="modifymessage"></u-button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				nickName:'',
				phonenumber:'',
				sex:'',
				actions:[
					{
						name:'男'
					},
					{
						name:'女'
					}
				],
				show:false,
				email:''
			}
		},
		onLoad() {
			this.getmessage()
		},
		methods: {
			getmessage(){
				this.api.get('/prod-api/api/common/user/getInfo').then(res=>{
					this.nickName=res.data.user.nickName
					this.phonenumber=res.data.user.phonenumber
					this.sex=res.data.user.sex
					this.email=res.data.user.email
				})
			},
			selectsex(e){
				this.sex=e.name
				console.log(this.sex)
			},
			modifymessage(){
				if(this.nickName===''||this.phonenumber===''||this.sex===''||this.email===''){
					uni.showModal({
						title:参数错误
					})
				}else{
					const message={
						email:this.email,
						nickName:this.nickName,
						phonenumber:this.phonenumber,
						sex:this.sex
					}
					this.api.get('/prod-api/api/common/user','PUT',message).then(res=>{
						console.log(res.data)
						if(res.data.code===200){
							setTimeout(function(){
								uni.showToast({
									title:'修改成功'
								})
							},700)
							uni.reLaunch({
								url:'/pages/me/me'
							})
						}else{
							setTimeout(function(){
								uni.showToast({
									title:'修改失败'
								})
							},700)
						}
					})
				}
			}
		}
	}
</script>

<style lang="scss">
.p2{
	margin-top: 15px;
	margin-bottom: 15px;
	display: flex;
}
</style>
